package com.spring.mvc.util;

/**
 * 字符串转换工具类
 * @author liujian
 *
 */
public class MathUtil {
	
	/**
	 * 将byte转为int
	 * @param b
	 * @return
	 */
	public static final int ub(byte b) {
		return ((b < 0) ? 256 + b : b);
	}

	/**
	 * 将字符串转为int
	 * @param s
	 * @return
	 */
	public static int toInt(String s) {
		return toInt(s, 10);
	}

	/**
	 * 以给定基数将字符串转换为int
	 * @param s
	 * @param radix
	 * @return
	 */
	public static int toInt(String s, int radix) {
		try {
			return Integer.parseInt(s, radix);
		} catch (Exception e) {
			return 0;
		}
	}

	/**
	 * 将字符串转为double
	 * @param s
	 * @return
	 */
	public static double toDouble(String s) {
		try {
			return Double.parseDouble(s);
		} catch (Exception e) {
			return 0D;
		}
	}

	/**
	 * 将
	 * @param s
	 * @return
	 */
	public static float toFloat(String s) {
		try {
			return Float.parseFloat(s);
		} catch (Exception e) {
			return 0F;
		}
	}

	public static long toLong(String s) {
		try {
			return Long.parseLong(s);
		} catch (Exception e) {
			return 0L;
		}
	}

	public static short toShort(String s) {
		try {
			return Short.parseShort(s);
		} catch (Exception e) {
			return 0;
		}
	}

	public static boolean toBoolean(String s) {
		Boolean obj;
		try {
			obj = new Boolean(s);
			return obj.booleanValue();
		} catch (Exception e) {
			return false;
		}
	}

	public static byte toByte(String s) {
		try {
			return Byte.parseByte(s);
		} catch (Exception e) {
			return 0;
		}
	}

	public static int C(int m, int n) {
		if ((n < 0) || (m < 0) || (n < m)) {
			return 0;
		}

		if (m == n) {
			return 1;
		}

		int i = 0;
		long result = 1L;
		if (n < 2 * m)
			m = n - m;

		for (i = n; i >= n - m + 1; --i)
			result *= i;

		for (i = m; i >= 2; --i)
			result /= i;

		return (int) result;
	}

	public static void main(String[] args) {
		System.out.println(C(0, 11));
	}
}